import React from 'react'
import PropTypes from 'prop-types'

const SwitchCase = ({ children, switchValue }) => {
  let match
  let child
  React.Children.forEach(children, (element) => {
    if (match == null) {
      const {
        name,
        value,
        defaultValue,
      } = element.props
      child = element
      if (switchValue === value) {
        match = true
      }
    }
  })
  return match
    ? React.cloneElement(child)
    : null
}

SwitchCase.propTypes = {
  children: PropTypes.node.isRequired,
  switchValue: PropTypes.string.isRequired,
}

export default SwitchCase
